<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Reflect的静态方法</title>
</head>
<body>
    <h1>Reflect的静态方法</h1>

    <script>
        // Reflect.get()
        const obj = { foo: 1, bar: 2 };
        console.log(Reflect.get(obj, 'foo')); // 1

        // Reflect.set()
        const obj2 = {};
        Reflect.set(obj2, 'prop', 'value');
        console.log(obj2.prop); // "value"

        // Reflect.has()
        const obj3 = { foo: 1 };
        console.log(Reflect.has(obj3, 'foo')); // true

        // Reflect.deleteProperty()
        const obj4 = { foo: 'bar' };
        Reflect.deleteProperty(obj4, 'foo');
        console.log(obj4.foo); // undefined

        // Reflect.construct()
        function User(name) {
            this.name = name;
        }
        const instance = Reflect.construct(User, ['张三']);
        console.log(instance.name); // "张三"

        // Reflect.getPrototypeOf()
        console.log(Reflect.getPrototypeOf(instance) === User.prototype); // true

        // Reflect.setPrototypeOf()
        const obj5 = {};
        Reflect.setPrototypeOf(obj5, Array.prototype);
        console.log(obj5.length); // 0
    </script>
</body>
</html> 